package com.imut.lagain.entity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

import java.time.LocalDateTime;

/**
 * 访问日志
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("access_log")
public class AccessLog {
    private static final Logger log = LoggerFactory.getLogger(AccessLog.class);

    
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    /**
     * 访问用户ID，不能为空，外键关联
     */
    @TableField("user_id")
    private Long userId;
    
    /**
     * 访问的URL路径
     */
    @NotBlank(message = "访问路径不能为空")
    @Size(max = 500, message = "访问路径长度不能超过500个字符")
    @TableField("path")
    private String path;
    
    /**
     * HTTP请求方法（GET, POST, PUT, DELETE等）
     */
    @NotBlank(message = "请求方法不能为空")
    @Size(max = 10, message = "请求方法长度不能超过10个字符")
    @TableField("method")
    private String method;
    
    /**
     * 客户端IP地址
     */
    @Size(max = 45, message = "IP地址长度不能超过45个字符")
    @TableField("ip_address")
    private String ipAddress;
    
    /**
     * 用户代理信息
     */
    @Size(max = 500, message = "用户代理信息长度不能超过500个字符")
    @TableField("user_agent")
    private String userAgent;
    
    /**
     * 来源URL
     */
    @Size(max = 500, message = "来源URL长度不能超过500个字符")
    @TableField("referer")
    private String referer;
    
    /**
     * 响应状态码
     */
    @TableField("status_code")
    private Integer statusCode;
    
    /**
     * 响应时间（毫秒）
     */
    @TableField("response_time")
    private Long responseTime;
    
    /**
     * 请求参数（JSON格式）
     */
    @TableField("request_params")
    private String requestParams;
    
    /**
     * 访问时间
     */
    @TableField(value = "access_time", fill = FieldFill.INSERT)
    private LocalDateTime accessTime;
    
    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public void setPath(String path) {
        this.path = path;
    }
    
    public void setMethod(String method) {
        this.method = method;
    }
    
    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }
    
    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }
    
    public void setReferer(String referer) {
        this.referer = referer;
    }
    
    public void setStatusCode(Integer statusCode) {
        this.statusCode = statusCode;
    }
    
    public void setResponseTime(Long responseTime) {
        this.responseTime = responseTime;
    }
    
    public void setRequestParams(String requestParams) {
        this.requestParams = requestParams;
    }
    
    public void setAccessTime(LocalDateTime accessTime) {
        this.accessTime = accessTime;
    }
    
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
}
